{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Skulpt Python as a Jupyter Notebook\n", "\n", "This is a Jupyter notebook running Skulpt Python. Although Skulpt Python runs in the browser, this Jupyter kernel also has the ability to run magics, can run shell commands (via MetaKernel), tab completions, and help.\n", "\n", "Why is this useful?\n", "\n", "For one thing, one can construct visualizations that are live in static notebooks. These visualizations can re-use code from a standard IPython Jupyter notebook.\n", "\n", "This example has each cell as Skulpt Python script. Skulpt Python is similar to Python 2.6." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " Canvas #5:
\n", "
\n",
       "      
\n", "
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "print \"Hello, world!\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Skulpt Python contains a turtle module:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " Canvas #6:
\n", "
\n",
       "      
\n", "
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import turtle\n", "\n", "t = turtle.Turtle()\n", "\n", "for c in ['red', 'green', 'yellow', 'blue']:\n", " t.color(c)\n", " t.forward(75)\n", " t.left(90)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Also, Skulpt Python has a processing module:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " Canvas #7:
\n", "
\n",
       "      
\n", "
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from processing import *\n", "\n", "def setup():\n", " size(400,400)\n", " noStroke()\n", " smooth()\n", " noLoop()\n", "\n", "def draw():\n", " drawCircle(200,170,6)\n", "\n", "def drawCircle(x, radius, level):\n", " tt = 128.0 * level / 4.0\n", " fill(tt)\n", " ellipse(x, 200, radius*2, radius*2)\n", " if level > 1:\n", " level = level - 1\n", " drawCircle(x - radius / 2, radius/2, level)\n", " drawCircle(x + radius / 2, radius/2, level)\n", "run() " ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " Canvas #8:
\n", "
\n",
       "      
\n", "
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from math import sin, sqrt\n", "from processing import *\n", "\n", "X = 30\n", "Y = 30\n", "delay = 16\n", "radius = 30\n", "\n", "def setup():\n", " strokeWeight(10)\n", " frameRate(20)\n", " size(300,300)\n", "\n", "def dist(x1,y1,x2,y2):\n", " o = y2-y1\n", " a = x2-x1\n", " return sqrt(o*o + a*a)\n", "\n", "def draw():\n", " background(51)\n", " strokeWeight(1)\n", " for i in range(0,environment.width,20):\n", " for j in range(0,environment.width,20):\n", " size = dist(mouse.x,mouse.y,i,j)\n", " size = size/dist(0,0,environment.height,environment.width) * 100\n", " ellipse(i,j,size,size)\n", "run()\n", " " ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Let's take a look at a static view." ] } ], "metadata": { "kernelspec": { "display_name": "Skulpt Python", "language": "python", "name": "skulpt_python" }, "language_info": { "codemirror_mode": { "name": "text/x-python", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }